<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePaymentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('payments', function (Blueprint $table) {
            $table->bigIncrements('payment_id');
            $table->string('order_bn', 100)->index()->comment('订单编号');
            $table->string('pay_no', 100)->comment('支付单号');
            $table->bigInteger('member_id')->comment('会员ID');
            $table->enum('type', ['payed','refund'])->default('payed')->comment('状态: payed 支付 refund 退款');
            $table->enum('status', ['ready', 'success','failed'])->default('ready')->comment('状态: ready 支付中 success 成功 failed 失败');
            $table->float('paid_amount', 8, 2)->default('0.00')->comment('支付金额');
            $table->float('discount_amount', 8, 2)->default('0.00')->comment('优惠金额');
            $table->string('payment_code', 100)->comment('支付方式');
            $table->text('pre_result')->nullable()->comment('统一支付创单');
            $table->text('pay_result')->nullable()->comment('网关支付');
            $table->text('pay_return')->nullable()->comment('支付回调');
            $table->text('remark')->nullable()->comment('备注');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('payments');
    }
}
